package com.atguigu.gulimall.order.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author 满超
 * @date 2020/06/16
 * 线程池
 **/
@Configuration
public class ThreadPoolConfig {

    @Bean
    public ThreadPoolExecutor threadPoolExecutor(ThreadProperties pool){
        return new ThreadPoolExecutor(
                pool.getSize(),//核心线程池大小
                pool.getMaxSize(),//最大核心线程池大小，需要根据机器获取
                pool.getSleepTime(),//超时释放
                TimeUnit.SECONDS,//超时单位
                new LinkedBlockingDeque<>(30000),//队列
                Executors.defaultThreadFactory(),//线程工厂
                new ThreadPoolExecutor.AbortPolicy()//拒绝策略
        );
    }
}
